cmake_minimum_required(VERSION 3.12)
project(rpc_framework)

# 强制C++17
set(CMAKE_CXX_STANDARD 17)

# 配置nlohmann_json（已验证存在）
find_package(nlohmann_json 3.0 REQUIRED)

# 配置Muduo（完全匹配您的实际路径）
set(MUDUO_INSTALL_DIR "$ENV{HOME}/studyDemo/RpcDemo/build/release-install-cpp11")
set(MUDUO_INCLUDE_DIR "${MUDUO_INSTALL_DIR}/include/muduo")  # 关键修正：添加/muduo后缀
set(MUDUO_LIB_DIR "${MUDUO_INSTALL_DIR}/lib")

# 核心库配置
add_library(rpc_framework STATIC
    src/json_serializer.cpp
    src/rpc_client.cpp
    src/rpc_server.cpp
)

# 关键修正：包含路径配置
target_include_directories(rpc_framework PUBLIC
    ${PROJECT_SOURCE_DIR}/include
    ${MUDUO_INCLUDE_DIR}  # 现在路径指向 .../include/muduo
)

target_link_libraries(rpc_framework PRIVATE
    ${MUDUO_LIB_DIR}/libmuduo_net.a
    ${MUDUO_LIB_DIR}/libmuduo_base.a
    pthread
    nlohmann_json::nlohmann_json
)

# 示例程序
add_executable(rpc_server_example example/server_example.cpp)
add_executable(rpc_client_example example/client_example.cpp)
target_link_libraries(rpc_server_example PRIVATE rpc_framework)
target_link_libraries(rpc_client_example PRIVATE rpc_framework)

# 打印验证信息
message(STATUS "Muduo头文件路径: ${MUDUO_INCLUDE_DIR}")
message(STATUS "Muduo库文件路径: ${MUDUO_LIB_DIR}")